<?php
namespace Admin\Controller;
use Think\Controller;
use Xml\MyTooA;
use Xml\MyTooB;
use Xml\User;
use Xml\EtooResources;
use Xml\EtooResourcesWarehouse;
//use xml\MyTooB;//引入命名空间需要，制定相应的类。




class LoginController extends Controller {
	
	/* function  __construct () {
		parent::__construct();
		print  "In constructor\n" ;
		$this -> name  =  "MyDestructableClass" ;
	}
	
	function  __destruct () {
		//session('[destroy]');
		var_dump( $_SERVER['REMOTE_ADDR']);
		var_dump(session_id());
		print  "Destroying "  .  $this -> name  .  "\n" ;
	}
	 */
	public function index() {
		
		if (IS_POST) {			
			switch($_POST["submit"])
			{
				
			case "登录" :
			{
			
			$login = array();
			if (I('user', null, false)) {
				
				$login['user']=I('user', null, false);
				$login['password']=md5(I('password', null, false));
				//$login['uid']=3;
				//echo $login['user'].":".$login['password'].":".$login['uid'];
				//var_dump($login);
				$user = M('User');
				$date=$user->where($login)->select();
				if ($date)
				{
					$login['per']=$date[0][per];
					
					//var_dump($login);
					session('auth', $login);
					
				    $this->success('登录成功', U('Index/index'));
				}else {
					echo "用户或者密码不正确";
					Vendor('Xml.Xml');
					$mytool = new MyTooA();
			        $mytool->callme();
				}
				
			}else{
				
				$this->error('登录用户不存在，或者密码错误',U('Login/index'));
			}
			    break;
			}
			case "注册新账号" :
			{
				$this->success('注册新账号', U('Xzh/index'));
				break;
			}
			
			default :
			{
			    break;
			}
			
			}
			
		} else {
						
			$this->display();//调用默认目录下的模板
		}
	}
	public function logout() {
		session('[destroy]');
		$this->success('退出成功', U('Login/index'));
	}
}